// api/commonUser.js
import { get, post, put, del } from '@/utils/request';

// 获取用户列表
export const fetchUsers = async (params) => {
  try {
    const response = await get('/users', { params });
    return response;
  } catch (error) {
    console.error('获取用户列表失败:', error);
    throw error;
  }
};

// 添加用户
export const addUser = async (user) => {
  try {
    const response = await post('/users', user);
    return response;
  } catch (error) {
    console.error('添加用户失败:', error);
    throw error;
  }
};

// 更新用户
export const updateUser = async (user) => {
  try {
    const response = await put(`/users/${user.id}`, user);
    return response;
  } catch (error) {
    console.error('更新用户失败:', error);
    throw error;
  }
};

// 删除用户
export const deleteUser = async (id) => {
  try {
    const response = await del(`/users/${id}`);
    return response;
  } catch (error) {
    console.error('删除用户失败:', error);
    throw error;
  }
};

// 获取用户总数
export const getTotalUsers = async (params) => {
  try {
    const response = await get('/users/count', { params });
    return response;
  } catch (error) {
    console.error('获取用户总数失败:', error);
    throw error;
  }
};